We'll focus on maps and cartrographic visualization. In this lab, you will practice:
After building these charts, you will make a website with these charts using streamlit.
import pandas as pd
import altair as alt
from vega_datasets import data
alt.data_transformers.disable_max_rows()
df = pd.read_csv('https://raw.githubusercontent.com/pratik-mangtani/si649-hw/main/airports.csv')
url = "https://raw.githubusercontent.com/pratik-mangtani/si649-hw/main/small-airports.json"
Description of the visualization:
We want to visualize the density of small airports in the world. Each small airport is represented by a dot. The visualization has two layers:
Hint:
df
| id | ident | type | name | latitude_deg | longitude_deg | elevation_ft | continent | iso_country | iso_region | municipality | scheduled_service | gps_code | iata_code | local_code | home_link | wikipedia_link | keywords | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 6523 | 00A | heliport | Total Rf Heliport | 40.070801 | -74.933601 | 11.0 | NaN | US | US-PA | Bensalem | no | 00A | NaN | 00A | NaN | NaN | NaN |
| 1 | 323361 | 00AA | small_airport | Aero B Ranch Airport | 38.704022 | -101.473911 | 3435.0 | NaN | US | US-KS | Leoti | no | 00AA | NaN | 00AA | NaN | NaN | NaN |
| 2 | 6524 | 00AK | small_airport | Lowell Field | 59.947733 | -151.692524 | 450.0 | NaN | US | US-AK | Anchor Point | no | 00AK | NaN | 00AK | NaN | NaN | NaN |
| 3 | 6525 | 00AL | small_airport | Epps Airpark | 34.864799 | -86.770302 | 820.0 | NaN | US | US-AL | Harvest | no | 00AL | NaN | 00AL | NaN | NaN | NaN |
| 4 | 506791 | 00AN | small_airport | Katmai Lodge Airport | 59.093287 | -156.456699 | 80.0 | NaN | US | US-AK | King Salmon | no | 00AN | NaN | 00AN | NaN | NaN | NaN |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 74751 | 46378 | ZZ-0001 | heliport | Sealand Helipad | 51.894444 | 1.482500 | 40.0 | EU | GB | GB-ENG | Sealand | no | NaN | NaN | NaN | http://www.sealandgov.org/ | https://en.wikipedia.org/wiki/Principality_of_... | Roughs Tower Helipad |
| 74752 | 307326 | ZZ-0002 | small_airport | Glorioso Islands Airstrip | -11.584278 | 47.296389 | 11.0 | AF | TF | TF-U-A | Grande Glorieuse | no | NaN | NaN | NaN | NaN | NaN | NaN |
| 74753 | 346788 | ZZ-0003 | small_airport | Fainting Goat Airport | 32.110587 | -97.356312 | 690.0 | NaN | US | US-TX | Blum | no | 87TX | NaN | 87TX | NaN | NaN | NaN |
| 74754 | 342102 | ZZZW | closed | Scandium City Heliport | 69.355287 | -138.939310 | 4.0 | NaN | CA | CA-YT | (Old) Scandium City | no | NaN | NaN | NaN | NaN | NaN | ZZZW, ZZZW, ZYW, YK96 |
| 74755 | 313629 | ZZZZ | small_airport | Satsuma Iōjima Airport | 30.784722 | 130.270556 | 338.0 | AS | JP | JP-46 | Mishima | no | RJX7 | NaN | RJX7 | NaN | http://wikimapia.org/6705190/Satsuma-Iwo-jima-... | SATSUMA,IWOJIMA,RJX7 |
74756 rows × 18 columns
small_airport = df[df['type'] == "small_airport"]
world = data.world_110m.url
land = alt.Chart(alt.topo_feature(world, 'countries')).transform_filter(alt.datum.id != 10).mark_geoshape(
fill='lightgray'
).project(
type='mercator'
)
# TODO: Vis 1
sa = alt.Chart(small_airport).mark_circle().encode(
longitude='longitude_deg:Q',
latitude='latitude_deg:Q',
size=alt.value(3),
color=alt.value('red'),
tooltip='name'
).project(
"mercator"
).properties(
width=500,
height=400
)
map = alt.layer(land, sa).properties(
width=600,
height=400
)
map